<template>
	<view class="content">
		<view style="height: 2rpx;"></view>
		<view class="wid90 mar borRad20 coFFF mar-top20" :style="'background-color: '+theme.main_color+';'">
			<view class="wid90 mar">
				<view class="hei86 dis disAl disJuB" style="border-bottom: 1rpx solid #fff;">
					<view class="fowe600 foSi30">查询时间</view>
					<picker mode="date" fields="month" :end="end" :value="date" @change="bindDateChange">
						<view class="dis disAl foSi25">
							<view class="fowe600 mar-right10" style="color: #fff;">{{chanfenStr(date)}}</view>
							<uni-icons type="right" size="25rpx" color="#fff"></uni-icons>
						</view>
					</picker>
				</view>
				<view class="dis disAl disJuB" style="height: 96rpx;">
					<view class="fowe600 foSi30">入账状态</view>
					<picker class="foSi25" @change="typeChange" :value="typeIndex" :range="typeList">
						<view class="dis disAl foSi25 fowe600">
							<view class="mar-right10">{{typeList[typeIndex]}}</view>
							<uni-icons type="right" size="25rpx" color="#fff"></uni-icons>
						</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="mar-top30 wid90 mar bacFFF borRad20" style="padding: 10rpx 0;">
			<view class="wid90 mar">
				<picker mode="date" fields="month" :end="end" :value="date" @change="bindDateChange">
					<view class="dis disAl hei60">
						<view class="fowe600 foSi30">{{chanfenStr(date)}}</view>
						<view class="mar-left30 dis disAl foSi20" style="color: #7A7A7A;">
							<view>切换</view>
							<uni-icons type="right" size="25rpx"></uni-icons>
						</view>
					</view>
				</picker>
				<view class="foSi20 webkitLineClamp" style="color: #7A7A7A;">获得总提成¥{{agent_statistics}}（{{iden}}）</view>
				<view style="height: 10rpx;"></view>
			</view>
		</view>
		<view class="wid90 mar bacFFF mar-top30 borRad20" v-for="(item,index) in list">
			<view class="wid90 mar">
				<view class="dis disAl disJuB" style="height: 100rpx;border-bottom: 1rpx solid #E5E5E5;">
					<view class="dis disAl">
						<view class="foSi25 mar-right20" style="color: #737373;">技师</view>
						<view class="fowe600 foSi30">{{item.tech_name}}</view>
					</view>
					<view class="fowe600 foSi25" :style="'color: '+theme.main_color+';'" v-if="item.service_status > 0 && item.service_status < 5">未到账</view>
					<view class="fowe600 foSi25" :style="'color: '+theme.main_color+';'" v-if="item.service_status >= 5">已到账</view>
				</view>
				<view class="foSi25" style="color: #5B5B5B;">
					<view class="mar-top10 hei60 dis disAl">
						<view style="width: 40%;">创建时间：</view>
						<view style="width: 60%;">{{item.createtime}}</view>
					</view>
					<view class="hei60 dis disAl">
						<view style="width: 40%;">服务时间：</view>
						<view style="width: 60%;">{{item.start_time == '' ? '未开始' : item.start_time}}</view>
					</view>
					<view class="hei60 dis disAl">
						<view style="width: 40%;">项目：</view>
						<view style="width: 60%;">{{item.service_name}}</view>
					</view>
					<view class="hei60 dis disAl">
						<view style="width: 40%;">订单实际支付：</view>
						<view style="width: 60%;">¥{{item.total_price}}</view>
					</view>
					<view class="hei60 dis disAl">
						<view style="width: 40%;">技师分成：</view>
						<view style="width: 60%;" :style="'color: '+theme.main_color+';'">¥{{item.tech_price}}</view>
					</view>
					<view class="hei60 dis disAl">
						<view style="width: 40%;">城市代理分成：</view>
						<view style="width: 60%;" :style="'color: '+theme.main_color+';'">¥{{item.agent_price}}</view>
					</view>
				</view>
				<view class="hei20"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				inquireDate: null,
				date: null,
				typeList: ['全部','已入账','未入账'],
				typeIndex: 0,
				theme: null,
				page:1,
				last_page:1,
				list:[],
				agent_statistics:0,
				iden:''
			}
		},
		onLoad() {
			this.date = this.dateFormat()
			this.end = this.dateFormat()
			this.theme = uni.getStorageSync('theme')
			this.getList()
			this.gettc()
		},
		onShow() {},
		methods: {
			inquireDateChange: function(e) {
				this.inquireDate = e.detail.value
			},
			typeChange: function(e) {
				this.typeIndex = e.detail.value
				this.page = 1
				this.list = []
				this.getList()
				this.gettc()
			},
			dateFormat(time) {
				let date = new Date();
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				// return year+"-"+month;
				return year + "-" + month + "-" + day;
			},
			chanfenStr(val){
				return val.split("-")[0]+'年'+val.split("-")[1]+'月'
			},
			bindDateChange: function(e) {
				var val = e.detail.value
				this.date = e.detail.value
				this.page = 1
				this.list = []
				this.getList()
				this.gettc()
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_smfw/agent/commission_details',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						page: that.page,
						agent_id:uni.getStorageSync('agent_id'),
						times:that.date,
						entry_status:that.typeIndex, // 入账状态1已入账2未入账
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}
					}
				})
			},
			gettc(){
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_smfw/agent/agent_statistics',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						page: that.page,
						agent_id:uni.getStorageSync('agent_id'),
						times:that.date,
						entry_status:that.typeIndex, // 入账状态1已入账2未入账
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.agent_statistics = result.data.money
							that.iden = result.data.iden
						}
					}
				})
				
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					// this.getList()
				}
			},
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F3F1F1;
	}
	.xia{
		height: 1rpx;
		background: #D2D2D2;
	}
</style>
